<?php

require '../vendor/autoload.php';


use Aws\DynamoDb\Exception\DynamoDbException;
use Aws\DynamoDb\Marshaler;

$sdk = new Aws\Sdk([
    'region'   => 'us-west-2',
    'version'  => 'latest',
    'credentials' => [
        'key' => 'AKIA4SBKFCJAXUOUXUN2',
        'secret' => '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',
    ],
]);

$dynamodb = $sdk->createDynamoDb();
$marshaler = new Marshaler();

$tableName = 'live';

$eav = $marshaler->marshalItem([':value'=>'618ce82659f1a']);//必须和KeyConditionExpression中定义的 :value一致

$params = [
    'TableName' => $tableName,
    'KeyConditionExpression' => '#fieldname = :value',// #fieldname 和 :value 都可以任意取名
    'ExpressionAttributeNames'=> [ '#fieldname' => 'channel_id' ],//绑定属性名，#fieldname对应上一行中的取的名字
    'ExpressionAttributeValues'=> $eav//绑定属性值
];


try {
    $result = $dynamodb->query($params);

    echo "Query succeeded.\n";

    foreach ($result['Items'] as $v) {
        var_dump($marshaler->unmarshalItem($v));
    }

} catch (DynamoDbException $e) {
    echo "Unable to query:\n";
    echo $e->getMessage() . "\n";
}